<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>审核活动</title>
    <link rel="stylesheet" href="https://www.layuicdn.com/layui/css/layui.css">
</head>
<body>

<table id="demo" lay-filter="test"></table>

<script src="https://www.layuicdn.com/layui/layui.js"></script>
<script>
    layui.use(['table', 'layer','jquery'], function () {
        var table = layui.table;
        var layer = layui.layer;
        let $ = layui.jquery;

        table.render({
            elem: '#demo',
            height: 'auto',
            url: '/activity/getApplyList', //数据接口,
            page: true, //开启分页
            cols: [[ //表头
                {field: 'actApplyId', title: '活动申请编号', width: "10%",fixed:'left'},
                {field: 'studentId', title: '学生学号', width: "10%"},
                {field: 'studentName', title: '学生姓名', width: "10%"},
                {field: 'studentAcademy', title: '学生学院', width: "10%"},
                {field: 'activityCategory', title: '活动种类', width: "10%"},
                {field: 'activityContent', title: '活动内容', width: "10%"},
                {field: 'activityAmount', title: '活动人数', width: "10%"},
                {field: 'startTime', title: '开始时间', width: "10%"},
                {field: 'closeTime', title: '结束时间', width: "10%"},
                {field: 'applyReason', title: '申请原因', width: "10%"},
                {field: 'applyDate', title: '申请日期', width: "10%"},
                {title: '操作', width: "15%", toolbar: '#barDemo',fixed:'right'},
            ]],
            response: {
                statusCode: 200,//规定成功的状态码，默认：0
            },
            parseData: function(res){ //res 即为原始返回的数据
                return {
                    "code": res.code, //解析接口状态
                    "count": res.data.total, //解析数据长度
                    "data": res.data.list //解析数据列表
                };
            }
        });

        table.on('tool(test)', function(obj){
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            if(layEvent === 'apply') { //申请
                action('1',data.actApplyId,obj)
            }else if (layEvent==='refuse'){
                action('2',data.actApplyId,obj)
            }
        })

        function action(status,actApplyId,obj) {
            $.post('/activity/saveApplyActivity',{'actApplyId':actApplyId,'status':status},response=>{
                if(response.code==='200'){
                    layer.msg('已同意');
                    obj.del()
                }else {
                    layer.msg(response.msg)
                }
            })
        }

    })
</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="apply">同意</a>
    <a class="layui-btn layui-btn-xs" lay-event="refuse">拒绝</a>
</script>
</body>
</html>